﻿using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.ExcelFill
{
    public class ExcelFillController : Controller
    {

        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            //定义Workbook对象
            PageOfficeNetCore.Excel.WorkbookWriter workBook = new PageOfficeNetCore.Excel.WorkbookWriter();
            //定义Sheet对象，"Sheet1"是打开的Excel表单的名称
            PageOfficeNetCore.Excel.SheetWriter sheet = workBook.OpenSheet("Sheet1");
            //定义Cell对象,给单元格赋值
            PageOfficeNetCore.Excel.ExcelCellWriter cellB4 = sheet.OpenCell("B4");
            cellB4.Value = "1月";
            //或者直接给Cell赋值
            sheet.OpenCell("C4").Value = "300";
            sheet.OpenCell("D4").Value = "270";
            sheet.OpenCell("E4").Value = "270";
            sheet.OpenCell("F4").Value = string.Format("{0:P}", 270.0 / 300);

            poCtrl.SetWriter(workBook);// 注意不要忘记此代码，如果缺少此句代码，不会赋值成功。
            //打开Excel文档
            poCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }


    }
}